﻿using AutoMapper;
using Common.Infrastructrue.Interface;
using Common.Service;
using MediatR;

namespace RabitPart.ReadApi.Application.RBACrelationship.RELUserShow
{
    public class UserShowCommanHandel : IRequestHandler<UserShowComman, ApiResult<IList<UserShowCommanResponstity>>>
    {
        private readonly IMapper mapper;
        private readonly IRel_user_roleResponstity useroleRE;
        private readonly IUserResponstity userRE;
        private readonly IRoleResponstity RoleRE;
        private readonly ILogger<UserShowCommanHandel> logger;
        public UserShowCommanHandel(IMapper mapper, IRel_user_roleResponstity useroleRE, IUserResponstity userRE, IRoleResponstity RoleRE, ILogger<UserShowCommanHandel> logger)
        {
            this.mapper = mapper;
            this.useroleRE = useroleRE;
            this.logger = logger;
            this.userRE = userRE;
            this.RoleRE = RoleRE;
        }


        public async Task<ApiResult<IList<UserShowCommanResponstity>>> Handle(UserShowComman request, CancellationToken cancellationToken)
        {

            var userlist =  ( await userRE.GetAllAsync()).AsQueryable();

            var list = mapper.Map<IList<UserShowCommanResponstity>>(userlist);

            return await Task.FromResult(ApiResult<IList<UserShowCommanResponstity>>.Success(list, StatusCodeEnum.Ok));
        }

    }
}
